package com.gxar.navigation.server.db.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gxar.navigation.server.base.model.activity.request.PreviewRequest;
import com.gxar.navigation.server.base.model.activity.request.PublishRequest;
import com.gxar.navigation.server.base.model.activity.response.PreviewResponse;
import com.gxar.navigation.server.base.model.activity.response.PublishResponse;
import com.gxar.navigation.server.base.reference.QiMenReference;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author linsy
 * @version 1.0
 * @created 2023/9/21 10:46
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ActivityService {

    private final QiMenReference qiMenReference;

    /**
     * 活动预览
     *
     * @param request 请求
     * @return 响应
     */
    public PreviewResponse preview(PreviewRequest request) {
        JSONObject jsonObject = qiMenReference.previewActivity(String.valueOf(request.getActiveId()));
        return JSON.parseObject(JSON.toJSONString(jsonObject), PreviewResponse.class);
    }

    /**
     * 活动发布
     *
     * @param request 请求
     * @return 响应
     */
    public PublishResponse publish(PublishRequest request) {
        JSONObject jsonObject = qiMenReference.publishActivity(String.valueOf(request.getActiveId()));
        return JSON.parseObject(JSON.toJSONString(jsonObject), PublishResponse.class);
    }



}
